package com.clubs.coding.Service.Impl;

import com.clubs.coding.Service.MakeTimeService;

import com.clubs.coding.exception.ImoocMallException;
import com.clubs.coding.exception.ImoocMallExceptionEnum;
import com.clubs.coding.model.dao.MakeTimeMapper;
import com.clubs.coding.model.pojo.MakeTime;
import com.clubs.coding.model.request.MakeTimeReq;
import com.clubs.coding.model.request.MakeTimeSelectReq;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class MakeTimeServiceImpl implements MakeTimeService {
    @Autowired
    MakeTimeMapper makeTimeMapper;
   @Override
public PageInfo list(MakeTimeSelectReq makeTimeSelectReq){
        PageHelper.startPage(makeTimeSelectReq.getPageNum(), makeTimeSelectReq.getPageSize());

    List<MakeTime> makeTime = makeTimeMapper.selectByClassify(makeTimeSelectReq);
        PageInfo pageInfo = new PageInfo(makeTime);
    return pageInfo;
}
@Override
    public void  upload(MakeTimeReq makeTimeReq){
        MakeTime makeTime = new MakeTime();
        BeanUtils.copyProperties(makeTimeReq,makeTime);

        int i = makeTimeMapper.insertSelective(makeTime);
        if (i==0) {
            throw new ImoocMallException(ImoocMallExceptionEnum.INSERT_FAILED);
        }
    }
}
